package com.learn.grpc.interceptor;

import com.learn.grpc.hello.HelloServiceGrpcImpl;
import io.grpc.Server;
import io.grpc.ServerBuilder;


/**
 * @author zongf
 * @since 2023-07-06
 **/
public class InterceptorGrpcServer {

    public static void main(String[] args) throws Exception{


        int serverPort = 9091;

        //1. 创建 server 构造器
        ServerBuilder<?> serverBuilder = ServerBuilder.forPort(serverPort);

        //2. 添加暴露的服务
        serverBuilder.addService(new HelloServiceGrpcImpl());

        serverBuilder.intercept(new MyServerRequestInterceptor());
        serverBuilder.intercept(new MyServerResponseInterceptor());

        //3. 构建 Server
        Server server = serverBuilder.build();

        //4. 启动服务
        server.start();

        System.out.println("服务启动成功...");

        server.awaitTermination();

    }

}
